import * as mysql2 from 'mysql2'
import connect from './connection/connect.js'
import endConn from './connection/end.js'
import configValues from './config/values.js'
import checkConfig from './config/check.js'
import types from './type/values.js'
import checkType from './type/check.js'
import checkColumns from './column/check.js'
import tableOpertions from './table/main.js'

class Mysql {
    /**
     * @type {mysql2.Connection}
     */
    connection = null

    /**
     * @param {import('./config/check.js').Config} config
     */
    constructor(config) {
        checkConfig(config)
        this.connection = connect(config, mysql2, checkConfig)
    }

    get table() {
        const connection = this.connection
        return tableOpertions(connection, checkType, checkColumns)
    }

    end() {
        return endConn(this.connection)
    }

    static TYPES = types
    static checkType = checkType
    static CONFIG_KEYS = configValues
    static checkConfig = checkConfig
    static checkColumns = checkColumns
}

export default Mysql;